package com.gnkexy.springframework.test.factory;

import com.gnkexy.springframework.beans.factory.config.BeanPostProcessor;
import com.gnkexy.springframework.test.bean.UserService;

public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        if ("userService".equals(beanName)) {
            System.out.println("执行：userService的BeanPostProcessor接口的postProcessBeforeInitialization方法");
            UserService userService = (UserService) bean;
            userService.setLocation("改为：北京");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        if ("userService".equals(beanName)) {
            System.out.println("执行：userService的BeanPostProcessor接口的postProcessAfterInitialization方法");
        }
        return bean;
    }
}
